{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1001\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  var force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  var JS_MIME_TYPE = 'application/javascript';\n",
       "  var HTML_MIME_TYPE = 'text/html';\n",
       "  var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  var CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    var script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    var cell = handle.cell;\n",
       "\n",
       "    var id = cell.output_area._bokeh_element_id;\n",
       "    var server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            var id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    var output_area = handle.output_area;\n",
       "    var output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      var bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      var script_attrs = bk_div.children[0].attributes;\n",
       "      for (var i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      var toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    var events = require('base/js/events');\n",
       "    var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  var NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    var el = document.getElementById(\"1001\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error() {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (var i = 0; i < css_urls.length; i++) {\n",
       "      var url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n",
       "\n",
       "    for (var i = 0; i < js_urls.length; i++) {\n",
       "      var url = js_urls[i];\n",
       "      var element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      if (url in hashes) {\n",
       "        element.crossOrigin = \"anonymous\";\n",
       "        element.integrity = \"sha384-\" + hashes[url];\n",
       "      }\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n",
       "  var css_urls = [];\n",
       "  \n",
       "\n",
       "  var inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (var i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      var cell = $(document.getElementById(\"1001\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  var force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  var NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    var el = document.getElementById(\"1001\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error() {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (var i = 0; i < css_urls.length; i++) {\n      var url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n\n    for (var i = 0; i < js_urls.length; i++) {\n      var url = js_urls[i];\n      var element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.async = false;\n      element.src = url;\n      if (url in hashes) {\n        element.crossOrigin = \"anonymous\";\n        element.integrity = \"sha384-\" + hashes[url];\n      }\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n  var css_urls = [];\n  \n\n  var inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (var i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      var cell = $(document.getElementById(\"1001\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import output_notebook,figure,show\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#https://blog.csdn.net/d1240673769/article/details/118881720  直方图参考"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 本周知识-柱状图"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 基本柱状图\n",
    "### 垂直柱状图 p.vbar（）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"5071be82-2f19-4e70-92f7-f28b4b6354db\" data-root-id=\"1002\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"7d7b3276-5286-473d-9504-b64f10710957\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1011\"}],\"center\":[{\"id\":\"1014\"},{\"id\":\"1018\"}],\"left\":[{\"id\":\"1015\"}],\"plot_height\":400,\"plot_width\":400,\"renderers\":[{\"id\":\"1036\"}],\"title\":{\"id\":\"1039\"},\"toolbar\":{\"id\":\"1026\"},\"x_range\":{\"id\":\"1003\"},\"x_scale\":{\"id\":\"1007\"},\"y_range\":{\"id\":\"1005\"},\"y_scale\":{\"id\":\"1009\"}},\"id\":\"1002\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1007\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1019\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1020\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1005\",\"type\":\"DataRange1d\"},{\"attributes\":{\"formatter\":{\"id\":\"1042\"},\"ticker\":{\"id\":\"1016\"}},\"id\":\"1015\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1009\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1012\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1011\"},\"ticker\":null},\"id\":\"1014\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1022\",\"type\":\"SaveTool\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1019\"},{\"id\":\"1020\"},{\"id\":\"1021\"},{\"id\":\"1022\"},{\"id\":\"1023\"},{\"id\":\"1024\"}]},\"id\":\"1026\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1023\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1042\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"1033\"}},\"id\":\"1037\",\"type\":\"CDSView\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1025\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1045\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"data\":{\"top\":[1.2,2.5,3.7],\"x\":[1,2,3]},\"selected\":{\"id\":\"1044\"},\"selection_policy\":{\"id\":\"1045\"}},\"id\":\"1033\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"data_source\":{\"id\":\"1033\"},\"glyph\":{\"id\":\"1034\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1035\"},\"selection_glyph\":null,\"view\":{\"id\":\"1037\"}},\"id\":\"1036\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1039\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1040\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"skyblue\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"skyblue\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1035\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1016\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1015\"},\"dimension\":1,\"ticker\":null},\"id\":\"1018\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1044\",\"type\":\"Selection\"},{\"attributes\":{\"overlay\":{\"id\":\"1025\"}},\"id\":\"1021\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1024\",\"type\":\"HelpTool\"},{\"attributes\":{\"fill_color\":{\"value\":\"skyblue\"},\"line_color\":{\"value\":\"skyblue\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1034\",\"type\":\"VBar\"},{\"attributes\":{\"formatter\":{\"id\":\"1040\"},\"ticker\":{\"id\":\"1012\"}},\"id\":\"1011\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1003\",\"type\":\"DataRange1d\"}],\"root_ids\":[\"1002\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"7d7b3276-5286-473d-9504-b64f10710957\",\"root_ids\":[\"1002\"],\"roots\":{\"1002\":\"5071be82-2f19-4e70-92f7-f28b4b6354db\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1002"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "p = figure(plot_width=400,plot_height=400)\n",
    "p.vbar(x=[1,2,3],width = 0.5,bottom = 0,\n",
    "      top=[1.2,2.5,3.7],color='skyblue')\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 水平柱状图 p.hbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"667138f7-7139-4afd-8282-5b2454ec5e76\" data-root-id=\"1101\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"2940abea-8b33-4d60-95eb-6887fa687954\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1110\"}],\"center\":[{\"id\":\"1113\"},{\"id\":\"1117\"}],\"left\":[{\"id\":\"1114\"}],\"plot_height\":400,\"plot_width\":400,\"renderers\":[{\"id\":\"1135\"}],\"title\":{\"id\":\"1147\"},\"toolbar\":{\"id\":\"1125\"},\"x_range\":{\"id\":\"1102\"},\"x_scale\":{\"id\":\"1106\"},\"y_range\":{\"id\":\"1104\"},\"y_scale\":{\"id\":\"1108\"}},\"id\":\"1101\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1153\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1152\",\"type\":\"Selection\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1124\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"fill_color\":{\"value\":\"LightPink\"},\"height\":{\"value\":0.5},\"line_color\":{\"value\":\"LightPink\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1133\",\"type\":\"HBar\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1147\",\"type\":\"Title\"},{\"attributes\":{\"data\":{\"right\":[1.2,2.5,3.7],\"y\":[1,2,3]},\"selected\":{\"id\":\"1152\"},\"selection_policy\":{\"id\":\"1153\"}},\"id\":\"1132\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1102\",\"type\":\"DataRange1d\"},{\"attributes\":{\"formatter\":{\"id\":\"1148\"},\"ticker\":{\"id\":\"1111\"}},\"id\":\"1110\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1106\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1104\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1108\",\"type\":\"LinearScale\"},{\"attributes\":{\"data_source\":{\"id\":\"1132\"},\"glyph\":{\"id\":\"1133\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1134\"},\"selection_glyph\":null,\"view\":{\"id\":\"1136\"}},\"id\":\"1135\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"source\":{\"id\":\"1132\"}},\"id\":\"1136\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1118\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1111\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1150\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"axis\":{\"id\":\"1110\"},\"ticker\":null},\"id\":\"1113\",\"type\":\"Grid\"},{\"attributes\":{\"formatter\":{\"id\":\"1150\"},\"ticker\":{\"id\":\"1115\"}},\"id\":\"1114\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1115\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1114\"},\"dimension\":1,\"ticker\":null},\"id\":\"1117\",\"type\":\"Grid\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1118\"},{\"id\":\"1119\"},{\"id\":\"1120\"},{\"id\":\"1121\"},{\"id\":\"1122\"},{\"id\":\"1123\"}]},\"id\":\"1125\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1148\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1119\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1123\",\"type\":\"HelpTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"LightPink\"},\"height\":{\"value\":0.5},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"LightPink\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1134\",\"type\":\"HBar\"},{\"attributes\":{\"overlay\":{\"id\":\"1124\"}},\"id\":\"1120\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1121\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1122\",\"type\":\"ResetTool\"}],\"root_ids\":[\"1101\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"2940abea-8b33-4d60-95eb-6887fa687954\",\"root_ids\":[\"1101\"],\"roots\":{\"1101\":\"667138f7-7139-4afd-8282-5b2454ec5e76\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1101"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "p = figure(plot_width=400,plot_height=400)\n",
    "p.hbar(y=[1,2,3],height = 0.5,left = 0,\n",
    "      right=[1.2,2.5,3.7],color='LightPink')  \n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 案例demo（1）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"061ae2e5-4e86-4629-9710-734baa7060eb\" data-root-id=\"1209\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"b6a47b92-f347-4f5c-9f0c-df66c85a835e\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1220\"}],\"center\":[{\"id\":\"1222\"},{\"id\":\"1226\"}],\"left\":[{\"id\":\"1223\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1244\"}],\"title\":{\"id\":\"1210\"},\"toolbar\":{\"id\":\"1234\"},\"x_range\":{\"id\":\"1212\"},\"x_scale\":{\"id\":\"1216\"},\"y_range\":{\"id\":\"1214\"},\"y_scale\":{\"id\":\"1218\"}},\"id\":\"1209\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1232\",\"type\":\"HelpTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1233\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"text\":\"Fruit Counts\"},\"id\":\"1210\",\"type\":\"Title\"},{\"attributes\":{\"overlay\":{\"id\":\"1233\"}},\"id\":\"1229\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1269\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1265\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"1267\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"1267\"},\"ticker\":{\"id\":\"1224\"}},\"id\":\"1223\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1230\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1221\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"1224\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1231\",\"type\":\"ResetTool\"},{\"attributes\":{\"source\":{\"id\":\"1241\"}},\"id\":\"1245\",\"type\":\"CDSView\"},{\"attributes\":{\"fill_color\":{\"value\":\"LightCoral\"},\"line_color\":{\"value\":\"LightCoral\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1242\",\"type\":\"VBar\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1227\"},{\"id\":\"1228\"},{\"id\":\"1229\"},{\"id\":\"1230\"},{\"id\":\"1231\"},{\"id\":\"1232\"}]},\"id\":\"1234\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1270\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1228\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"LightCoral\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"LightCoral\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1243\",\"type\":\"VBar\"},{\"attributes\":{\"data_source\":{\"id\":\"1241\"},\"glyph\":{\"id\":\"1242\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1243\"},\"selection_glyph\":null,\"view\":{\"id\":\"1245\"}},\"id\":\"1244\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis\":{\"id\":\"1223\"},\"dimension\":1,\"ticker\":null},\"id\":\"1226\",\"type\":\"Grid\"},{\"attributes\":{\"axis\":{\"id\":\"1220\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1222\",\"type\":\"Grid\"},{\"attributes\":{\"factors\":[\"apple\",\"pears\",\"nectarines\",\"plums\",\"grapes\",\"strawberries\"]},\"id\":\"1212\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1216\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"1227\",\"type\":\"PanTool\"},{\"attributes\":{\"data\":{\"top\":[5,3,4,2,4,6],\"x\":[\"apple\",\"pears\",\"nectarines\",\"plums\",\"grapes\",\"strawberries\"]},\"selected\":{\"id\":\"1269\"},\"selection_policy\":{\"id\":\"1270\"}},\"id\":\"1241\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"formatter\":{\"id\":\"1265\"},\"ticker\":{\"id\":\"1221\"}},\"id\":\"1220\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1218\",\"type\":\"LinearScale\"},{\"attributes\":{\"start\":0},\"id\":\"1214\",\"type\":\"DataRange1d\"}],\"root_ids\":[\"1209\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"b6a47b92-f347-4f5c-9f0c-df66c85a835e\",\"root_ids\":[\"1209\"],\"roots\":{\"1209\":\"061ae2e5-4e86-4629-9710-734baa7060eb\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1209"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 数据\n",
    "fruit = ['apple','pears','nectarines','plums','grapes','strawberries']\n",
    "counts = [5,3,4,2,4,6]\n",
    "#画布\n",
    "p = figure(x_range=fruit,plot_height=350,title='Fruit Counts')  #x_range=fruits设置x轴数值\n",
    "\n",
    "# 柱状图\n",
    "p.vbar(x = fruit,top = counts,width = 0.9,color='LightCoral')\n",
    "\n",
    "# 坐标轴设置\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"4f571057-4b0d-4d3d-8026-bcd72655aed1\" data-root-id=\"1320\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"5d9e372d-b703-40d9-b25f-79ec1736fcee\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1331\"}],\"center\":[{\"id\":\"1333\"},{\"id\":\"1337\"}],\"left\":[{\"id\":\"1334\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1355\"}],\"title\":{\"id\":\"1321\"},\"toolbar\":{\"id\":\"1345\"},\"x_range\":{\"id\":\"1323\"},\"x_scale\":{\"id\":\"1327\"},\"y_range\":{\"id\":\"1325\"},\"y_scale\":{\"id\":\"1329\"}},\"id\":\"1320\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"text\":\"Fruit Counts\"},\"id\":\"1321\",\"type\":\"Title\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"LightCoral\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"LightCoral\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1354\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1343\",\"type\":\"HelpTool\"},{\"attributes\":{\"data\":{\"top\":[5,3,4,2,4,6],\"x\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"selected\":{\"id\":\"1388\"},\"selection_policy\":{\"id\":\"1389\"}},\"id\":\"1352\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"factors\":[\"Plums\",\"Pears\",\"Nectarines\",\"Grapes\",\"Apples\",\"Strawberries\"]},\"id\":\"1323\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1341\",\"type\":\"SaveTool\"},{\"attributes\":{\"formatter\":{\"id\":\"1386\"},\"ticker\":{\"id\":\"1335\"}},\"id\":\"1334\",\"type\":\"LinearAxis\"},{\"attributes\":{\"axis\":{\"id\":\"1331\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1333\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1329\",\"type\":\"LinearScale\"},{\"attributes\":{\"formatter\":{\"id\":\"1384\"},\"ticker\":{\"id\":\"1332\"}},\"id\":\"1331\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1384\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"1332\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"1335\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1389\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1327\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"fill_color\":{\"value\":\"LightCoral\"},\"line_color\":{\"value\":\"LightCoral\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1353\",\"type\":\"VBar\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1338\"},{\"id\":\"1339\"},{\"id\":\"1340\"},{\"id\":\"1341\"},{\"id\":\"1342\"},{\"id\":\"1343\"}]},\"id\":\"1345\",\"type\":\"Toolbar\"},{\"attributes\":{\"data_source\":{\"id\":\"1352\"},\"glyph\":{\"id\":\"1353\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1354\"},\"selection_glyph\":null,\"view\":{\"id\":\"1356\"}},\"id\":\"1355\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"source\":{\"id\":\"1352\"}},\"id\":\"1356\",\"type\":\"CDSView\"},{\"attributes\":{\"overlay\":{\"id\":\"1344\"}},\"id\":\"1340\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1344\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"axis\":{\"id\":\"1334\"},\"dimension\":1,\"ticker\":null},\"id\":\"1337\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1342\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1386\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"start\":0},\"id\":\"1325\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1338\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1388\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1339\",\"type\":\"WheelZoomTool\"}],\"root_ids\":[\"1320\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"5d9e372d-b703-40d9-b25f-79ec1736fcee\",\"root_ids\":[\"1320\"],\"roots\":{\"1320\":\"4f571057-4b0d-4d3d-8026-bcd72655aed1\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1320"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 数据\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "counts = [5, 3, 4, 2, 4, 6]\n",
    "# 排序\n",
    "sorted_fruits = sorted(fruits, key=lambda x: counts[fruits.index(x)])\n",
    "# 画布\n",
    "p = figure(x_range=sorted_fruits, plot_height=350, title=\"Fruit Counts\",\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 绘图\n",
    "p.vbar(x=fruits, top=counts, width=0.9,color='LightCoral')\n",
    "# 其他\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 案例demo（2）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"28d76d87-020b-4688-9d3a-fc33d92cc9a5\" data-root-id=\"1440\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"38edbcc1-aa33-4fdb-a7fc-633452e0ccc4\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1451\"}],\"center\":[{\"id\":\"1453\"},{\"id\":\"1457\"}],\"left\":[{\"id\":\"1454\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1477\"}],\"title\":{\"id\":\"1441\"},\"toolbar\":{\"id\":\"1466\"},\"x_range\":{\"id\":\"1443\"},\"x_scale\":{\"id\":\"1447\"},\"y_range\":{\"id\":\"1445\"},\"y_scale\":{\"id\":\"1449\"}},\"id\":\"1440\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1455\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1516\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1459\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1464\"}},\"id\":\"1460\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"start\":0},\"id\":\"1445\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis\":{\"id\":\"1454\"},\"dimension\":1,\"ticker\":null},\"id\":\"1457\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1463\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1518\",\"type\":\"Selection\"},{\"attributes\":{\"formatter\":{\"id\":\"1516\"},\"ticker\":{\"id\":\"1455\"}},\"id\":\"1454\",\"type\":\"LinearAxis\"},{\"attributes\":{\"axis\":{\"id\":\"1451\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1453\",\"type\":\"Grid\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1464\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1514\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"1439\"}},\"id\":\"1478\",\"type\":\"CDSView\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"LightCoral\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"LightCoral\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1476\",\"type\":\"VBar\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"count\",\"@counts\"]]},\"id\":\"1465\",\"type\":\"HoverTool\"},{\"attributes\":{\"formatter\":{\"id\":\"1514\"},\"ticker\":{\"id\":\"1452\"}},\"id\":\"1451\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"factors\":[\"apple\",\"pears\",\"nectarines\",\"plums\",\"grapes\",\"strawberries\"]},\"id\":\"1443\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1462\",\"type\":\"ResetTool\"},{\"attributes\":{\"data\":{\"counts\":[5,3,4,2,4,6],\"x\":[\"apple\",\"pears\",\"nectarines\",\"plums\",\"grapes\",\"strawberries\"]},\"selected\":{\"id\":\"1518\"},\"selection_policy\":{\"id\":\"1519\"}},\"id\":\"1439\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1458\",\"type\":\"PanTool\"},{\"attributes\":{\"fill_color\":{\"value\":\"LightCoral\"},\"line_color\":{\"value\":\"LightCoral\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1475\",\"type\":\"VBar\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1458\"},{\"id\":\"1459\"},{\"id\":\"1460\"},{\"id\":\"1461\"},{\"id\":\"1462\"},{\"id\":\"1463\"},{\"id\":\"1465\"}]},\"id\":\"1466\",\"type\":\"Toolbar\"},{\"attributes\":{\"data_source\":{\"id\":\"1439\"},\"glyph\":{\"id\":\"1475\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1476\"},\"selection_glyph\":null,\"view\":{\"id\":\"1478\"}},\"id\":\"1477\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1452\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"1519\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"text\":\"Fruit Counts\"},\"id\":\"1441\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1461\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1447\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"1449\",\"type\":\"LinearScale\"}],\"root_ids\":[\"1440\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"38edbcc1-aa33-4fdb-a7fc-633452e0ccc4\",\"root_ids\":[\"1440\"],\"roots\":{\"1440\":\"28d76d87-020b-4688-9d3a-fc33d92cc9a5\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1440"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "\n",
    "# 数据\n",
    "fruit = ['apple','pears','nectarines','plums','grapes','strawberries']\n",
    "counts = [5,3,4,2,4,6]\n",
    "\n",
    "#排序\n",
    "#sorted_fruit=sorted(fruit,key=lambda x: counts[fruit.index(x)])\n",
    "source = ColumnDataSource(\n",
    "    data = dict(\n",
    "    x=fruit,\n",
    "    counts = counts)\n",
    ")\n",
    "\n",
    "TOOLTIPS = [\n",
    "    ('count',\"@counts\")\n",
    "]\n",
    "#画布\n",
    "p = figure(x_range=fruit,plot_height=350,title='Fruit Counts',tooltips=TOOLTIPS)  #x_range=fruits设置x轴数值\n",
    "\n",
    "# 柱状图\n",
    "p.vbar(x = 'x',top = 'counts',width = 0.9,color='LightCoral',source=source)\n",
    "\n",
    "# 坐标轴设置\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 实践（1）2019年7月常见可视化工具Github标星数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using data directory: C:\\Users\\18018\\.bokeh\\data\n",
      "Skipping 'CGM.csv' (checksum match)\n",
      "Skipping 'US_Counties.zip' (checksum match)\n",
      "Skipping 'us_cities.json' (checksum match)\n",
      "Skipping 'unemployment09.csv' (checksum match)\n",
      "Skipping 'AAPL.csv' (checksum match)\n",
      "Skipping 'FB.csv' (checksum match)\n",
      "Skipping 'GOOG.csv' (checksum match)\n",
      "Skipping 'IBM.csv' (checksum match)\n",
      "Skipping 'MSFT.csv' (checksum match)\n",
      "Skipping 'WPP2012_SA_DB03_POPULATION_QUINQUENNIAL.zip' (checksum match)\n",
      "Skipping 'gapminder_fertility.csv' (checksum match)\n",
      "Skipping 'gapminder_population.csv' (checksum match)\n",
      "Skipping 'gapminder_life_expectancy.csv' (checksum match)\n",
      "Skipping 'gapminder_regions.csv' (checksum match)\n",
      "Skipping 'world_cities.zip' (checksum match)\n",
      "Skipping 'airports.json' (checksum match)\n",
      "Skipping 'movies.db.zip' (checksum match)\n",
      "Skipping 'airports.csv' (checksum match)\n",
      "Skipping 'routes.csv' (checksum match)\n",
      "Skipping 'haarcascade_frontalface_default.xml' (checksum match)\n"
     ]
    }
   ],
   "source": [
    "import bokeh\n",
    "bokeh.sampledata.download()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "#C:\\Users\\18018\\.bokeh\\data 数据路径"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"1da233f7-3f86-41fa-99de-84fe359146d4\" data-root-id=\"1569\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"9a14c115-f58d-4070-a8b5-10f506b321d4\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1580\"}],\"center\":[{\"id\":\"1582\"},{\"id\":\"1586\"}],\"left\":[{\"id\":\"1583\"}],\"renderers\":[{\"id\":\"1604\"}],\"title\":{\"id\":\"1570\"},\"toolbar\":{\"id\":\"1594\"},\"x_range\":{\"id\":\"1572\"},\"x_scale\":{\"id\":\"1576\"},\"y_range\":{\"id\":\"1574\"},\"y_scale\":{\"id\":\"1578\"}},\"id\":\"1569\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1587\"},{\"id\":\"1588\"},{\"id\":\"1589\"},{\"id\":\"1590\"},{\"id\":\"1591\"},{\"id\":\"1592\"}]},\"id\":\"1594\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1590\",\"type\":\"SaveTool\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1572\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1592\",\"type\":\"HelpTool\"},{\"attributes\":{\"formatter\":{\"id\":\"1651\"},\"ticker\":{\"id\":\"1584\"}},\"id\":\"1583\",\"type\":\"LinearAxis\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1593\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1651\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"data_source\":{\"id\":\"1601\"},\"glyph\":{\"id\":\"1602\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1603\"},\"selection_glyph\":null,\"view\":{\"id\":\"1605\"}},\"id\":\"1604\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1654\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"source\":{\"id\":\"1601\"}},\"id\":\"1605\",\"type\":\"CDSView\"},{\"attributes\":{\"axis\":{\"id\":\"1583\"},\"dimension\":1,\"ticker\":null},\"id\":\"1586\",\"type\":\"Grid\"},{\"attributes\":{\"data\":{\"fill_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"line_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"top\":[9678,11034,5387,6038,4928,3783],\"x\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1653\"},\"selection_policy\":{\"id\":\"1654\"}},\"id\":\"1601\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1588\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"start\":0},\"id\":\"1574\",\"type\":\"DataRange1d\"},{\"attributes\":{\"fill_color\":{\"field\":\"fill_color\"},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1602\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1581\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"1576\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"fill_color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1603\",\"type\":\"VBar\"},{\"attributes\":{\"text\":\"2019\\u5e747\\u6708\\u5e38\\u89c1\\u53ef\\u89c6\\u5316\\u5de5\\u5177Github\\u6807\\u661f\\u6570\\u91cf\"},\"id\":\"1570\",\"type\":\"Title\"},{\"attributes\":{\"overlay\":{\"id\":\"1593\"}},\"id\":\"1589\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"1580\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1582\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1591\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1578\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1653\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1584\",\"type\":\"BasicTicker\"},{\"attributes\":{\"formatter\":{\"id\":\"1649\"},\"ticker\":{\"id\":\"1581\"}},\"id\":\"1580\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1587\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1649\",\"type\":\"CategoricalTickFormatter\"}],\"root_ids\":[\"1569\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"9a14c115-f58d-4070-a8b5-10f506b321d4\",\"root_ids\":[\"1569\"],\"roots\":{\"1569\":\"1da233f7-3f86-41fa-99de-84fe359146d4\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1569"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "from bokeh.palettes import Spectral6\n",
    "import pandas as pd\n",
    "df=pd.read_csv('visualization-20190505.csv')\n",
    "p = figure(x_range=df['Visualization_tools'],title=\"2019年7月常见可视化工具Github标星数量\")\n",
    "p.vbar(x=df['Visualization_tools'], top=df['Star'] , width=0.8, color=Spectral6) \n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Visualization_tools</th>\n",
       "      <th>Watch</th>\n",
       "      <th>Star</th>\n",
       "      <th>Fork</th>\n",
       "      <th>Commits</th>\n",
       "      <th>Contributors</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>matplotlib</td>\n",
       "      <td>533</td>\n",
       "      <td>9678</td>\n",
       "      <td>4143</td>\n",
       "      <td>29503</td>\n",
       "      <td>808</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>bokeh</td>\n",
       "      <td>396</td>\n",
       "      <td>11034</td>\n",
       "      <td>2526</td>\n",
       "      <td>17673</td>\n",
       "      <td>357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>pyecharts</td>\n",
       "      <td>263</td>\n",
       "      <td>5387</td>\n",
       "      <td>1148</td>\n",
       "      <td>1321</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>seaborn</td>\n",
       "      <td>234</td>\n",
       "      <td>6038</td>\n",
       "      <td>970</td>\n",
       "      <td>2316</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>plotly</td>\n",
       "      <td>234</td>\n",
       "      <td>4928</td>\n",
       "      <td>1114</td>\n",
       "      <td>3370</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ggplot2</td>\n",
       "      <td>329</td>\n",
       "      <td>3783</td>\n",
       "      <td>1427</td>\n",
       "      <td>4286</td>\n",
       "      <td>184</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Visualization_tools  Watch   Star  Fork  Commits  Contributors\n",
       "0          matplotlib    533   9678  4143    29503           808\n",
       "1               bokeh    396  11034  2526    17673           357\n",
       "2           pyecharts    263   5387  1148     1321            18\n",
       "3             seaborn    234   6038   970     2316            98\n",
       "4              plotly    234   4928  1114     3370            76\n",
       "5             ggplot2    329   3783  1427     4286           184"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "pd.read_csv('visualization-20190505.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "df=pd.read_csv('visualization-20190505.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 颜色映射(细节)\n",
    "\n",
    "* 图例设置\n",
    ">p.legend.orientation = \"horizontal\"  水平放置\n",
    ">\n",
    ">p.legend.location = \"top_center\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"eedd0a4a-e259-4a17-a2fb-2153e6300a8e\" data-root-id=\"1705\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"aae20bf8-834d-4f13-9e2c-854ae69ac682\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1716\"}],\"center\":[{\"id\":\"1718\"},{\"id\":\"1722\"},{\"id\":\"1752\"}],\"left\":[{\"id\":\"1719\"}],\"plot_height\":500,\"renderers\":[{\"id\":\"1742\"}],\"title\":{\"id\":\"1706\"},\"toolbar\":{\"id\":\"1731\"},\"x_range\":{\"id\":\"1708\"},\"x_scale\":{\"id\":\"1712\"},\"y_range\":{\"id\":\"1710\"},\"y_scale\":{\"id\":\"1714\"}},\"id\":\"1705\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"fill_color\":{\"field\":\"color\"},\"line_color\":{\"field\":\"color\"},\"top\":{\"field\":\"y\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1740\",\"type\":\"VBar\"},{\"attributes\":{\"text\":\"\\u53ef\\u89c6\\u5316\\u5de5\\u5177flok\\u503c\"},\"id\":\"1706\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1749\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1750\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"Flok\",\"@y\"],[\"comment\",\"@comt\"],[\"contributors\",\"@con\"]]},\"id\":\"1730\",\"type\":\"HoverTool\"},{\"attributes\":{\"axis\":{\"id\":\"1716\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1718\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1745\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"end\":5000,\"start\":0},\"id\":\"1710\",\"type\":\"DataRange1d\"},{\"attributes\":{\"data\":{\"color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"comt\":[29503,17673,1321,2316,3370,4286],\"con\":[808,357,18,98,76,184],\"x\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"],\"y\":[4143,2526,1148,970,1114,1427]},\"selected\":{\"id\":\"1749\"},\"selection_policy\":{\"id\":\"1750\"}},\"id\":\"1704\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"formatter\":{\"id\":\"1747\"},\"ticker\":{\"id\":\"1720\"}},\"id\":\"1719\",\"type\":\"LinearAxis\"},{\"attributes\":{\"items\":[{\"id\":\"1753\"}],\"location\":\"top_center\",\"orientation\":\"horizontal\"},\"id\":\"1752\",\"type\":\"Legend\"},{\"attributes\":{\"data_source\":{\"id\":\"1704\"},\"glyph\":{\"id\":\"1740\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1741\"},\"selection_glyph\":null,\"view\":{\"id\":\"1743\"}},\"id\":\"1742\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1747\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1723\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1724\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1717\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"color\"},\"top\":{\"field\":\"y\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1741\",\"type\":\"VBar\"},{\"attributes\":{\"label\":{\"field\":\"x\"},\"renderers\":[{\"id\":\"1742\"}]},\"id\":\"1753\",\"type\":\"LegendItem\"},{\"attributes\":{\"formatter\":{\"id\":\"1745\"},\"ticker\":{\"id\":\"1717\"}},\"id\":\"1716\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1728\",\"type\":\"HelpTool\"},{\"attributes\":{\"axis\":{\"id\":\"1719\"},\"dimension\":1,\"ticker\":null},\"id\":\"1722\",\"type\":\"Grid\"},{\"attributes\":{\"overlay\":{\"id\":\"1729\"}},\"id\":\"1725\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1726\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1727\",\"type\":\"ResetTool\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1723\"},{\"id\":\"1724\"},{\"id\":\"1725\"},{\"id\":\"1726\"},{\"id\":\"1727\"},{\"id\":\"1728\"},{\"id\":\"1730\"}]},\"id\":\"1731\",\"type\":\"Toolbar\"},{\"attributes\":{\"source\":{\"id\":\"1704\"}},\"id\":\"1743\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1712\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"1714\",\"type\":\"LinearScale\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1729\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1720\",\"type\":\"BasicTicker\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1708\",\"type\":\"FactorRange\"}],\"root_ids\":[\"1705\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"aae20bf8-834d-4f13-9e2c-854ae69ac682\",\"root_ids\":[\"1705\"],\"roots\":{\"1705\":\"eedd0a4a-e259-4a17-a2fb-2153e6300a8e\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1705"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "from bokeh.palettes import Spectral6\n",
    "from bokeh.transform import factor_cmap\n",
    "\n",
    "#调色板 https://docs.bokeh.org/en/latest/docs/reference/palettes.html\n",
    "# 数据\n",
    "x = df['Visualization_tools']\n",
    "y = df['Fork']\n",
    "comt=df['Commits']\n",
    "con = df['Contributors']\n",
    "source = ColumnDataSource(\n",
    "    data = dict(\n",
    "    x=x,\n",
    "    y = y,\n",
    "    comt=comt,\n",
    "    con=con,\n",
    "    color=Spectral6\n",
    "    )\n",
    ")\n",
    "\n",
    "TOOLTIPS = [\n",
    "    ('Flok',\"@y\"),\n",
    "    ('comment',\"@comt\"),\n",
    "    ('contributors',\"@con\")\n",
    "    \n",
    "]\n",
    "\n",
    "#画布\n",
    "p = figure(x_range=x,plot_height=500,title='可视化工具flok值',tooltips=TOOLTIPS)  #x_range=fruits设置x轴数值\n",
    "\n",
    "# 柱状图\n",
    "p.vbar(x = 'x',top = 'y',width = 0.9,color='color',source=source,legend='x')\n",
    "\n",
    "#color=Spectral6 不可直接用 ，颜色列表也应存进source\n",
    "\n",
    "# 坐标轴设置\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "p.legend.orientation = \"horizontal\"  #颜色映射(细节)\n",
    "p.legend.location = \"top_center\"\n",
    "p.y_range.end=5000\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"de1f83b3-8e98-4308-8f3e-a292ff94e094\" data-root-id=\"1862\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"25de6ece-9463-469e-be22-ffa2f9393c8d\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1872\"}],\"center\":[{\"id\":\"1874\"},{\"id\":\"1878\"}],\"left\":[{\"id\":\"1875\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1896\"}],\"title\":{\"id\":\"1863\"},\"toolbar\":{\"id\":\"1886\"},\"x_range\":{\"id\":\"1861\"},\"x_scale\":{\"id\":\"1868\"},\"y_range\":{\"id\":\"1866\"},\"y_scale\":{\"id\":\"1870\"}},\"id\":\"1862\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1884\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1873\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"1868\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"1959\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1957\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"1957\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"1873\"}},\"id\":\"1872\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1961\",\"type\":\"Selection\"},{\"attributes\":{\"formatter\":{\"id\":\"1959\"},\"ticker\":{\"id\":\"1876\"}},\"id\":\"1875\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1880\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"source\":{\"id\":\"1860\"}},\"id\":\"1897\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1962\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1876\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1875\"},\"dimension\":1,\"ticker\":null},\"id\":\"1878\",\"type\":\"Grid\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1879\"},{\"id\":\"1880\"},{\"id\":\"1881\"},{\"id\":\"1882\"},{\"id\":\"1883\"},{\"id\":\"1884\"}]},\"id\":\"1886\",\"type\":\"Toolbar\"},{\"attributes\":{\"data_source\":{\"id\":\"1860\"},\"glyph\":{\"id\":\"1894\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1895\"},\"selection_glyph\":null,\"view\":{\"id\":\"1897\"}},\"id\":\"1896\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1885\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"factors\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]],\"range_padding\":0.1},\"id\":\"1861\",\"type\":\"FactorRange\"},{\"attributes\":{\"data\":{\"counts\":[2,5,3,1,3,2,4,3,4,3,2,4,2,4,5,4,6,3],\"x\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]]},\"selected\":{\"id\":\"1961\"},\"selection_policy\":{\"id\":\"1962\"}},\"id\":\"1860\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1882\",\"type\":\"SaveTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1895\",\"type\":\"VBar\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"1863\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1879\",\"type\":\"PanTool\"},{\"attributes\":{\"axis\":{\"id\":\"1872\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1874\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1883\",\"type\":\"ResetTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1885\"}},\"id\":\"1881\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1894\",\"type\":\"VBar\"},{\"attributes\":{\"start\":0},\"id\":\"1866\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1870\",\"type\":\"LinearScale\"}],\"root_ids\":[\"1862\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"25de6ece-9463-469e-be22-ffa2f9393c8d\",\"root_ids\":[\"1862\"],\"roots\":{\"1862\":\"de1f83b3-8e98-4308-8f3e-a292ff94e094\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1862"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource, FactorRange\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "years = ['2015', '2016', '2017']\n",
    "data = {'fruits' : fruits,\n",
    "        '2015'   : [2, 1, 4, 3, 2, 4],\n",
    "        '2016'   : [5, 3, 3, 2, 4, 6],\n",
    "        '2017'   : [3, 2, 4, 4, 5, 3]}\n",
    "# 创建复合列表 [ (\"Apples\", \"2015\"), (\"Apples\", \"2016\"), (\"Apples\", \"2017\"), (\"Pears\", \"2015), ... ]\n",
    "x = [ (fruit, year) for fruit in fruits for year in years ]\n",
    "counts = sum(zip(data['2015'], data['2016'], data['2017']), ()) # 分组求和(堆叠总数)\n",
    "source = ColumnDataSource(data=dict(x=x, counts=counts))\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=350, title=\"Fruit Counts by Year\",\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 柱状图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source)\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 课后实践 （star commits contribution）分组柱状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['matplotlib', 'bokeh', 'pyecharts', 'seaborn', 'plotly', 'ggplot2']"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    29503\n",
       "1    17673\n",
       "2     1321\n",
       "3     2316\n",
       "4     3370\n",
       "5     4286\n",
       "Name: Commits, dtype: int64"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "comt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"113a35a1-845b-445b-b3fb-3d4d64c6bfae\" data-root-id=\"3770\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"35ec3dce-cc20-4a5c-83d5-d09e34ee7e63\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"3780\"}],\"center\":[{\"id\":\"3782\"},{\"id\":\"3786\"}],\"left\":[{\"id\":\"3783\"}],\"plot_height\":400,\"renderers\":[{\"id\":\"3806\"}],\"title\":{\"id\":\"3771\"},\"toolbar\":{\"id\":\"3795\"},\"x_range\":{\"id\":\"3769\"},\"x_scale\":{\"id\":\"3776\"},\"y_range\":{\"id\":\"3774\"},\"y_scale\":{\"id\":\"3778\"}},\"id\":\"3770\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"],[\"ggplot2\",\"Contributors\"]],\"range_padding\":0.1},\"id\":\"3769\",\"type\":\"FactorRange\"},{\"attributes\":{\"data\":{\"counts\":[9678,29503,808,11034,17673,357,5387,1321,18,6038,2316,98,4928,3370,76,3783,4286,184],\"lt\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"],[\"ggplot2\",\"Contributors\"]]},\"selected\":{\"id\":\"3951\"},\"selection_policy\":{\"id\":\"3952\"}},\"id\":\"3768\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"3790\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"3952\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"axis\":{\"id\":\"3783\"},\"dimension\":1,\"ticker\":null},\"id\":\"3786\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"3776\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"3947\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"data_source\":{\"id\":\"3768\"},\"glyph\":{\"id\":\"3804\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"3805\"},\"selection_glyph\":null,\"view\":{\"id\":\"3807\"}},\"id\":\"3806\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"3787\"},{\"id\":\"3788\"},{\"id\":\"3789\"},{\"id\":\"3790\"},{\"id\":\"3791\"},{\"id\":\"3792\"},{\"id\":\"3794\"}]},\"id\":\"3795\",\"type\":\"Toolbar\"},{\"attributes\":{\"formatter\":{\"id\":\"3947\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"3781\"}},\"id\":\"3780\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"3787\",\"type\":\"PanTool\"},{\"attributes\":{\"fill_color\":{\"value\":\"skyblue\"},\"line_color\":{\"value\":\"skyblue\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"lt\"}},\"id\":\"3804\",\"type\":\"VBar\"},{\"attributes\":{\"axis\":{\"id\":\"3780\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"3782\",\"type\":\"Grid\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"3793\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"3792\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"3791\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"3951\",\"type\":\"Selection\"},{\"attributes\":{\"overlay\":{\"id\":\"3793\"}},\"id\":\"3789\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"text\":\"2019\\u5e745\\u6708\\u5e38\\u89c1\\u53ef\\u89c6\\u5316\\u5de5\\u5177\\u6e90\\u7801Github\\u6570\\u636e\"},\"id\":\"3771\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"3949\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"3778\",\"type\":\"LinearScale\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"star\",\"@s\"],[\"Commits\",\"@comt\"],[\"contributors\",\"@con\"]]},\"id\":\"3794\",\"type\":\"HoverTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"skyblue\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"skyblue\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"lt\"}},\"id\":\"3805\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"3784\",\"type\":\"BasicTicker\"},{\"attributes\":{\"end\":32000,\"start\":0},\"id\":\"3774\",\"type\":\"DataRange1d\"},{\"attributes\":{\"source\":{\"id\":\"3768\"}},\"id\":\"3807\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"3788\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"3781\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"formatter\":{\"id\":\"3949\"},\"ticker\":{\"id\":\"3784\"}},\"id\":\"3783\",\"type\":\"LinearAxis\"}],\"root_ids\":[\"3770\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"35ec3dce-cc20-4a5c-83d5-d09e34ee7e63\",\"root_ids\":[\"3770\"],\"roots\":{\"3770\":\"113a35a1-845b-445b-b3fb-3d4d64c6bfae\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "3770"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource, FactorRange\n",
    "from bokeh.palettes import Spectral6\n",
    "from bokeh.transform import factor_cmap\n",
    "\n",
    "x = df['Visualization_tools']\n",
    "xx = ['Star','Commits','Contributors']\n",
    "s = df['Star']\n",
    "comt=df['Commits']\n",
    "con = df['Contributors']\n",
    "\n",
    "source1 = ColumnDataSource(\n",
    "    data = dict(\n",
    "    \n",
    "    star=s,\n",
    "    comt=comt,\n",
    "    con=con,\n",
    "    color=Spectral6\n",
    "    )\n",
    ")\n",
    "TOOLTIPS = [\n",
    "    ('star',\"@s\"),\n",
    "    ('Commits',\"@comt\"),\n",
    "    ('contributors',\"@con\")\n",
    "    \n",
    "]\n",
    "\n",
    "data = {'x' : x,\n",
    "        'Star'   : s,\n",
    "        'Commits'   :comt ,\n",
    "        'Contributors'   : con}\n",
    "\n",
    "lt=[(x1,x2) for x1 in x for x2 in xx]\n",
    "counts = sum(zip(data['Star'],data['Commits'],data['Contributors']),())\n",
    "source = ColumnDataSource(data=dict(lt=lt, counts=counts))  #,s=s,comt=comt,con=con\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*lt), plot_height=400,title=\"2019年5月常见可视化工具源码Github数据\",tooltips=TOOLTIPS)#,tooltips=TOOLTIPS\n",
    "# 柱状图\n",
    "p.vbar(x='lt', top='counts', width=0.9, source=source,color='skyblue')\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "#p.legend.orientation='horizontal'\n",
    "#p.legend.location='top_center'\n",
    "p.y_range.end=32000\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
